#pragma once

#include "common.h"

//​将内核空间的帧缓冲映射到用户空间，需要两个数据接收帧缓冲的长度和地址，我们需要自己定义一个结构体,其中iVideoBufMaxLen接收帧缓冲的长度，pucVideBuf接收帧缓冲地址
class VideoDevice 
{
public:  
    VideoDevice();
    ~VideoDevice();
    int Init(const char*argv[]);
    int v4l2_cap();
    int v4l2_input();
    int v4l2_fmt();
    int v4l2_reqbufs();
    int v4l2_streamon();
    int v4l2_qbuf();
    int v4l2_dqbuf();
    int v4l2_streamoff();
    int v4l2_video_handle();

    void new_rgb_data();
    void image_show(const char* filename);
    void yuyv_to_rgb(unsigned char* yuyv_data, unsigned char* rgb_data, int width, int height);
    void resizeRGB(unsigned char* rgb_data, int width, int height, unsigned char* resized_rgb_data, int new_width, int new_height);
    void save_rgb_image(const char* filename, unsigned char* rgb_data, int width, int height);
    void save_rgb_video(const char* filename, unsigned char* rgb_data, int fps, int number_fps, int width, int height);

    int clamp(int value);
    void yuyv_to_rgb2(unsigned char *yuv_data, unsigned char *rgb_data, int width, int height);

    void print_rgb_data_as_hex(unsigned char* rgb_data);

    int iFd;
    int iPixelFormat;
    int iWidth;
    int iHeight;
    int iVideoBufCnt;
    int iVideoBufMaxLen;
    int iVideoBufCurIndex;
    unsigned char *pucVideBuf[NB_BUFFER];
    unsigned char *rgb_data[NB_BUFFER];
    unsigned char *resized_rgb_data[NB_BUFFER];

    int number;
    cv::VideoWriter writer;
};
